/**
 * 使用 requestAnimationFrame 进行节流
 */
export const rafThrottle = (fn) => {
  let rafId = null
  return (...args) => {
    if (rafId !== null) {
      cancelAnimationFrame(rafId)
    }
    rafId = requestAnimationFrame(() => {
      fn(...args)
      rafId = null
    })
  }
}

/**
 * 防抖函数
 */
export const debounce = (fn, delay) => {
  let timeoutId = null
  return (...args) => {
    if (timeoutId !== null) {
      clearTimeout(timeoutId)
    }
    timeoutId = setTimeout(() => {
      fn(...args)
      timeoutId = null
    }, delay)
  }
} 